/*
 * @Timur Suleimanov, Kiev 2012
 * Anagram
 */

import java.util.Arrays;
import java.util.Scanner;

public class Anagram {
	
	public static char[] sortCharArray(String sentence){
		sentence = sentence.trim().replaceAll("\\s+", "");
        char[] charArray = sentence.toLowerCase().toCharArray();
		Arrays.sort(charArray);
        return charArray;
	}
    
    public static boolean isAnagram(String firstSentence, String secondSentence){
		char firstSortedArray[] = sortCharArray(firstSentence);
		char secondSortedArray[] = sortCharArray(secondSentence);
        return Arrays.equals(firstSortedArray,secondSortedArray);  
    }
	
	public static void resultDisplay(String phraseOne, String phraseTwo){
		 if (isAnagram(phraseOne, phraseTwo))
            System.out.println(" And they are anagrams");
        else System.out.println(" And they are NOT anagrams");
	}
	
    public static void main(String[] args) { 
        String phraseOne;
        String phraseTwo;
        Scanner firstScan = new Scanner(System.in);
        System.out.println("Please input first phrase ");
        phraseOne = firstScan.nextLine();
        Scanner secondScan = new Scanner(System.in);
        System.out.println("Please input second phrase ");
        phraseTwo = secondScan.nextLine();
        System.out.println("Your words are " + phraseOne+" and "+phraseTwo);
		resultDisplay(phraseOne,phraseTwo);
    }
}
